package com.taotao.service;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 客户端服务续约
 */
public class ServiceRenewal {
    private ScheduledExecutorService scheduledService = Executors.newSingleThreadScheduledExecutor();
    private static final Log log = LogFactory.getLog(ServiceRenewal.class);

    /**
     * 客户端服务续约线程什么时候启动？
     * 服务注册完成之后
     */
    public void start() {
        log.info("服务续约线程启动...");
        scheduledService.scheduleAtFixedRate(new ServiceRenewalThread(), 3, 3, TimeUnit.SECONDS);
    }

    @Autowired
    private RegisterService registerService;

    /**
     * 服务续约线程
     */
    class ServiceRenewalThread implements Runnable {
        @Override
        public void run() {
            registerService.renewal();
        }
    }
}